package com.liukai.bishe.ui.viewHolder.listener.impl;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.liukai.bishe.model.doman.transaction.Transaction;
import com.liukai.bishe.model.doman.transaction.TransactionTotal;
import com.liukai.bishe.presenter.transactionPresenter.ITransactionPresenter;
import com.liukai.bishe.ui.activity.CountDownActivity;
import com.liukai.bishe.ui.dialog.TransactionInfoDialog;
import com.liukai.bishe.ui.viewHolder.listener.TransactionOnClickListener;
import com.liukai.bishe.utils.Constants;
import com.liukai.bishe.utils.ToastUtil;

import java.util.List;

public class TransactionOnClickListenerImpl implements TransactionOnClickListener {

    private Context mContext;

    public TransactionOnClickListenerImpl(Context context) {
        this.mContext = context;
    }

    /**
     * 开始事务
     * @param view
     * @param transaction
     */
    @Override
    public void onStartTransationListener(View view, Transaction transaction) {
        view.setOnClickListener(view1 -> {
            ToastUtil.show(mContext,"开始");
            ToastUtil.log(mContext,"transaction=========>",transaction.toString());
            Intent intent = new Intent(mContext,CountDownActivity.class);
            intent.putExtra("transaction",transaction);
            mContext.startActivity(intent); // 开启时倒计时，进入倒计时页面
        });
    }

    /**
     * 事务长按事件监听
     * @param itemView
     * @param transaction
     * @param iTransactionPresenter
     */
    @Override
    public void onItemViewOnLongClickListener(View itemView,
                                              Transaction transaction,
                                              ITransactionPresenter iTransactionPresenter) {
//        ToastUtil.show(mContext,"长按");

        String id = transaction.getId();
        List<TransactionTotal> transactionTotals = Constants.getTransactionTotalList();
        TransactionTotal transactionTotal = new TransactionTotal();
        for (int i = 0;i < transactionTotals.size();i ++){
            if(id.equals(transactionTotals.get(i).getId())){
                transactionTotal = transactionTotals.get(i);
                break;
            }
        }

        TransactionInfoDialog transactionInfoDialog = new TransactionInfoDialog(mContext,
                transaction,transactionTotal,iTransactionPresenter);
        transactionInfoDialog.show();



    }


}
